﻿using CcrFlows.Core;
using NUnit.Framework;

namespace Test.CcrFlows.Samples
{
    [TestFixture]
    public class testSample1
    {
        [Test]
        public void Create_nested_flow()
        {
            var flow = new ForkedFlow<int>()
                        .Do<int, int>(
                            new ForkedFlow<int>()
                                .Do<int, int>(
                                    (i, pi)=>pi.Post(i+1),
                                    FlowHandlers.Copy<int>())
                                .Join<int>((i0, i1, pi)=>pi.Post(i0*10+i1))
                                .Do<int>((i, pi) => pi.Post(i + 1)),
                            Flow<int>.Copy()
                            )
                        .Join<string>((i0, i1, pi)=>pi.Post(i0 + "/" + i1));

            flow.Input.Post(1);

            string t;
            Assert.IsTrue(flow.Output.WaitFor(500, out t));
            Assert.AreEqual("22/1", t);
        }
    }
}
